package com.lgj.gateway.exceptions;

import com.lgj.result.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebExceptionHandler;
import reactor.core.publisher.Mono;

/**
 * @author: guangjie.liao
 * @Date: 2023/8/24 23:18
 * @Description: gateway 统一全局异常处理
 */
@Slf4j
@Component
@Order(-1)
public class GatewayGlobalExceptionHandler implements WebExceptionHandler {

    @Override
    public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
        log.error("异常信息：{}", ex.getMessage());
        log.error("异常堆栈信息：{}",ex.getStackTrace());
        return ResultBody.fail(exchange.getResponse());
    }
}
